package com.i2bt.adapter;

import com.i2bt.R;
import com.i2bt.app.files.FilesMoveActivity;
import com.i2bt.bean.FileInfoBean;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import java.util.ArrayList;
import java.util.List;

public class FilesMoveAdapter extends BaseAdapter {
	
	private FilesMoveActivity activity; // 文件移动活动类
	
	private List<FileInfoBean> filesMoveData; // 文件夹信息
	
	public FilesMoveAdapter(FilesMoveActivity activity, List<FileInfoBean> filesMoveData) {
		this.activity = activity;
		if (filesMoveData == null) {
			filesMoveData = new ArrayList<FileInfoBean>();
			filesMoveData.add(new FileInfoBean("aa", 1000, false));
			filesMoveData.add(new FileInfoBean("cccc", 1000, false));
		}
		this.filesMoveData = filesMoveData;
	}

	@Override
	public int getCount() {
		return filesMoveData.size();
	}

	@Override
	public Object getItem(int position) {
		return filesMoveData.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		
		ViewHolder holder = null;
		if (convertView == null) {
			convertView = LayoutInflater.from(activity).inflate(
					R.layout.item_files_move_list, null, false);
			
			holder = new ViewHolder();
			holder.filesMoveImg = (ImageView) convertView.findViewById(
					R.id.files_move_item_img);
			holder.filesMoveName = (TextView) convertView.findViewById(
					R.id.files_move_item_name);
			
			convertView.setTag(holder);
		}
		else {
			holder = (ViewHolder) convertView.getTag();
		}
		
		//消除黄色标记
		holder.filesMoveImg = holder.filesMoveImg;
		
		// 显示文件夹名
		FileInfoBean fileInfoBean = filesMoveData.get(position);
		holder.filesMoveName.setText(fileInfoBean.getFileName());
		
		return convertView;
	}
	
	private class ViewHolder {
		
		ImageView filesMoveImg;
		
		TextView filesMoveName;
		
	}
	
	/**
	 * 文件夹数据
	 * @param filesMoveData
	 */
	public void setData(List<FileInfoBean> filesMoveData) {
		this.filesMoveData = filesMoveData;
		notifyDataSetInvalidated();
	}
	
}
